﻿var rowNum = $('p[id^=rowNum]').length;

function addRow(frm) {
    rowNum++;

    var row = '' +
        '<p id="rowNum-' + rowNum + '">' +
        '   Ingredient: <select name="ingr" id="ingr-select-' + rowNum + '" class="form-control" style="width: 20%; display: initial"></select>' +
        '   Quantity: <input type="number" min="0" name="quant" class="form-control" style="width: 20%; display: initial"/>' +
        '   Unit: <select name="unit" id="unit-select-' + rowNum + '" class="form-control" style="width: 20%; display: initial"></select>' +
        '   <input type="button" class="btn btn-success" value="Remove" onclick="removeRow(' + rowNum + ');">' +
        '</p>';
    jQuery('#itemRows').append(row);

    var $optionsingr = $("#ingr-head-select > option").clone();
    var $optionsunit = $("#unit-head-select > option").clone();

    $('#ingr-select-' + rowNum).append($optionsingr);
    $('#unit-select-' + rowNum).append($optionsunit);

}

function removeRow(rnum) {
    jQuery('#rowNum-' + rnum).remove();
}

window.setTimeout(function () {
    $(".flash").fadeTo(500, 0).slideUp(500, function () {
        $(this).remove();
    });
}, 5000);
